﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Server
{
    public class Server
    {
        private FactoryMessage.STGMSG oMsg;
        private GPCS.GPCS_PERSONNE Gpcs_personne;
        private GPCS.GPCS_Sites Gpcs_listeSite;

        public FactoryMessage.STGMSG service(FactoryMessage.STGMSG oMsg)
        {
            if (this.secu_access_plateForme(oMsg.P_security))
            {
                if (oMsg.Invoke == "p_authentifier")
                {
                    this.Gpcs_personne = new GPCS.GPCS_PERSONNE();
                    this.oMsg = this.Gpcs_personne.p_authentifier(oMsg);
                }
                else if (oMsg.Invoke == "d_authentifier")
                {
                    this.Gpcs_personne = new GPCS.GPCS_PERSONNE();
                    this.oMsg = this.Gpcs_personne.d_authentifier(oMsg);
                }
                else if (oMsg.Invoke == "p_listeSite")
                {
                    this.Gpcs_listeSite = new GPCS.GPCS_Sites();
                    this.oMsg = this.Gpcs_listeSite.p_listeSite(oMsg);
                }
                else if (oMsg.Invoke == "d_listeSite")
                {

                }
                else if (oMsg.Invoke == "p_nouveauSite")
                {
                    this.Gpcs_listeSite = new GPCS.GPCS_Sites();
                    this.oMsg = this.Gpcs_listeSite.p_nouveauSite(oMsg);
                }
                else if (oMsg.Invoke == "d_nouveauSite")
                {

                }
                else if (oMsg.Invoke == "p_nv_personne")
                {
                    this.Gpcs_personne = new GPCS.GPCS_PERSONNE();
                    this.oMsg = this.Gpcs_personne.p_nv_personne(oMsg);
                }
                else if (oMsg.Invoke == "d_nv_personne")
                {

                }
                else if (oMsg.Invoke == "p_employesSite")
                {
                    this.Gpcs_listeSite = new GPCS.GPCS_Sites();
                    this.oMsg = this.Gpcs_listeSite.p_employesSite(oMsg);
                }

                else if (oMsg.Invoke == "p_ListeEmployes")
                {
                    this.Gpcs_personne = new GPCS.GPCS_PERSONNE();
                    this.oMsg = this.Gpcs_personne.p_ListeEmployes(oMsg);
                }
                else
                {
                    this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", null, "Le service demandé n'existe pas", null, null, false, "");
                }
            }
            else
            {
                this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", null, "Echec de connexion à la plateforme", null, null, false, "");
            }
            return this.oMsg;
        }

        private bool secu_access_plateForme(string keY)
        {
            bool valid;
            valid = false;
            if (keY == "@1234")
            {
                valid = true;
            }
            return valid;
        }
    }
}